<template>
  <PerfectTableComponent
    :loadTableList="loadTableList"
    :changePageSize="changePageSize"
    :changePage="changePage"
    :removeQueryField="removeQueryField"
    :clearQuery="clearQuery"
    v-model:query="query"
    title="移库日志"
    ref="tableRef"
    :queryFormHeaders="queryFormHeaders"
    :table="table"
    :tableColumns="tableColumns"
    :allowEditTableCell="false"
    :showTableIndex="false"
    :showOperatorColumn="false"
    :showDeleteButton="false"
    :showAddNewButton="false"
    :baseUrl="urls.API_URL_BACKSTAGE_WMS_WMSMATERIALINVENTORYDETAILRELOCATIONLOG"
    v-model:form="form"
    :formHeader="formHeader"
  >
    <!-----------------------------表格查询表单自定义元素----------------------------------------->
    <template #query_form_warehouseIdOfSource>
      <WmsWarehouseCascadeSelectComponent
        ref="wmsWarehouseCascadeSelectQueryComponentRef1"
        v-model:warehouseId="query['warehouseSeatOfSource.warehouseArea.warehouse.id']"
        v-model:warehouseAreaId="query['warehouseSeatOfSource.warehouseArea.id']"
        v-model:warehouseSeatId="query['warehouseSeatOfSource.id']"
      />
    </template>
    <template #query_form_warehouseIdOfTarget>
      <WmsWarehouseCascadeSelectComponent
        ref="wmsWarehouseCascadeSelectQueryComponentRef2"
        v-model:warehouseId="query['warehouseSeatOfTarget.warehouseArea.warehouse.id']"
        v-model:warehouseAreaId="query['warehouseSeatOfTarget.warehouseArea.id']"
        v-model:warehouseSeatId="query['warehouseSeatOfTarget.id']"
      />
    </template>
    <!-----------------------------表格自定义列----------------------------------------->
    <!--所属栏目1-->
    <template #table_column_materialName="scope: any">
      {{ scope.row.materialBatch != null ? scope.row.materialBatch.material.name : '' }}
    </template>
    <template #table_column_materialTypeName="scope: any">
      {{ scope.row.materialBatch != null ? scope.row.materialBatch.material.materialType.name : '' }}
    </template>
    <template #table_column_batchNumber="scope: any">
      {{ scope.row.materialBatch != null ? scope.row.materialBatch.batchNumber : '' }}
    </template>
    <!-- 库区-->
    <!-- <template #table_column_areaNumber="scope: any">
      <el-link
        type="primary"
        @click="
          router.push({
            path: '/backstage/wms/warehousearea',
            query: {
              warehouseId: scope.row.id
            }
          })
        "
        >{{ scope.row.areaNumber }}</el-link
      >
    </template> -->
    <!-- 库位-->
    <!-- <template #table_column_seatNumber="scope: any">
      <el-link
        type="primary"
        @click="
          router.push({
            path: '/backstage/wms/warehouseseat',
            query: {
              warehouseId: scope.row.id
            }
          })
        "
        >{{ scope.row.seatNumber }}</el-link
      >
    </template> -->
    <!-----------------------------表格自定义列（操作列）----------------------------------------->
    <!-- <template #table_operator_left="scope">
      <el-button
        @click="
          router.push({
            path: '/backstage/wms/warehousearea',
            query: {
              warehouseId: scope.row.id
            }
          })
        "
        type="primary"
        size="small"
        icon="House"
        plain
        >库区</el-button
      >
    </template> -->
  </PerfectTableComponent>
</template>

<script setup lang="ts">
import PerfectTableComponent from '@/components/base/table/PerfectTableComponent.vue';
import { onMounted, provide, reactive, ref } from 'vue';
import useTableList from '@/api/hooks/useTableList';
import type { FormHeader, ResponseData, TableColumn } from '@/types/interface/base_interface';
import urls from '@/api/request/urls';
import { getDict } from '@/api/dict';
import type { Warehouse } from '@/types/interface/wms_interface';
import Request from '@/api/request/request';
import { useRouter } from 'vue-router';
// 导入路由
const router = useRouter(); // 创建路由对象

// 表格工具必备参数
const { table, query, loadTableList, removeQueryField, clearQuery, changePageSize, changePage } = useTableList(
  urls.API_URL_BACKSTAGE_WMS_WMSMATERIALINVENTORYDETAILRELOCATIONLOG
);
// 将表格刷新函数传到子容器
provide('loadTableList', loadTableList);

//查询==========================================================
const queryFormHeaders = ref<FormHeader[]>([]);

//表格==========================================================
// 表格插件ref对象1
const tableRef = ref();

//表格列
// 定义表格所有的列字段信息
const tableColumns = ref<TableColumn[]>([]);

//表单==========================================================
//表单对象
const form = ref<Warehouse>({});
//表单元素类型
const formHeader = ref<FormHeader[]>([]);

onMounted(async () => {
  //定义优先级选项。放在mounted中执行时，要将引用改变量的属性也放进来。
  const relocationTypeDict = await getDict('移库动作', 'number');
  queryFormHeaders.value = [
    // 查询表单
    {
      prop: 'materialBatch.material.name',
      label: '物料名称'
    },
    {
      prop: 'materialBatch.id',
      label: '物料批次',
      type: 'selectRemote',
      width: '300px',
      url: urls.API_URL_BACKSTAGE_WMS_WMSMATERIALBATCH,
      queryNameForUrl: 'material.name',
      config: {
        valueKey: 'id',
        defaultProp: {
          value: 'id',
          label: '{material.name}（批次号：{batchNumber}）',
          labelRegexType: 2
          // label: '{material.name}（|批次号：{batchNumber}）'
          // label: 'material.name|batchNumber'
          // label: '物料：{material.name}'
        }
      }
    },
    {
      label: '移库动作',
      prop: 'relocationType',
      type: 'select',
      list: relocationTypeDict
    },
    {
      prop: 'warehouseIdOfSource',
      label: '源库位',
      propAsNames: ['warehouseSeatOfSource.warehouseArea.warehouse.id', 'warehouseSeatOfSource.warehouseArea.id', 'warehouseSeatOfSource.id'],
      type: 'custom'
    },
    {
      prop: 'warehouseIdOfTarget',
      label: '目标库位',
      propAsNames: ['warehouseSeatOfTarget.warehouseArea.warehouse.id', 'warehouseSeatOfTarget.warehouseArea.id', 'warehouseSeatOfTarget.id'],
      type: 'custom'
    }
  ];
  //表格对象
  tableColumns.value = [
    {
      label: '物料名',
      prop: 'materialName',
      type: 'custom',
      width: 200,
      fixed: true
    },
    {
      label: '物料类别',
      prop: 'materialTypeName',
      type: 'custom',
      width: 150,
      fixed: true
    },
    {
      label: '物料批次',
      prop: 'batchNumber',
      type: 'custom',
      width: 100,
      fixed: true
    },
    {
      label: '库存动作',
      prop: 'action',
      width: 100,
      fixed: true
    },
    {
      label: '库存变动',
      prop: 'actionDescription',
      width: 800
    },
    {
      label: '移库理由',
      prop: 'reason',
      width: 200
    },
    {
      label: '移库时间',
      prop: 'transferTime',
      width: 180
    }
  ];
});
</script>

<style scoped></style>
